package pl.olap.dao;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
@Entity
@Table(name = "person")
public class Person extends BaseEntity {
	private static final long serialVersionUID = 1L;
	private static final int NORMAL_LENGTH = 255;
	private static final int DESCRIPTION_LENGTH = 4000;
	
	@Id
	private PersonPK ID;
		
	@ManyToMany(fetch = FetchType.LAZY, mappedBy = "persons")
	private List<Movie> movies;

	/**
	 * @param firstName
	 * @param lastName
	 */
	public Person(String firstName, String lastName) {
		if(ID==null){
			ID = new PersonPK();
		}
		this.ID.setFirstName(firstName);
		this.ID.setLastName(lastName);
	}
	public Person(){
		
	}

	/**
	 * @return the firstName
	 */
	@Transient
	public String getFirstName() {
		if(ID==null){
			ID = new PersonPK();
		}
		return ID.getFirstName();
	}

	/**
	 * @return the lastName
	 */
	@Transient
	public String getLastName() {
		if(ID==null){
			ID = new PersonPK();
		}
		return ID.getLastName();
	}

	/**
	 * @param firstName the firstName to set
	 */
	public void setFirstName(String firstName) {
		if(ID==null){
			ID = new PersonPK();
		}
		this.ID.setFirstName(firstName);
	}

	/**
	 * @param lastName the lastName to set
	 */
	public void setLastName(String lastName) {
		if(ID==null){
			ID = new PersonPK();
		}
		this.ID.setLastName(lastName);
	}

	public void setMovies(List<Movie> movies) {
		this.movies = movies;
	}

	public List<Movie> getMovies() {
		return movies;
	}
	/**
	 * @return the iD
	 */
	public PersonPK getID() {
		return ID;
	}
	/**
	 * @param iD the iD to set
	 */
	public void setID(PersonPK iD) {
		ID = iD;
	}
	

}
